﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Web;

namespace Aide45
{
    public class AdslConnManager
    {
        public bool Reconnection()
        {
            Disconnection();
            return Connection();
        }

        public bool Connection()
        {
            var result = true;

            var adslName = ConfigurationManager.AppSettings["AdslName"];
            var account = ConfigurationManager.AppSettings["Account"];
            var pwd = ConfigurationManager.AppSettings["Pwd"];
            if (string.IsNullOrEmpty(adslName))
            {
                return false;
            }

            AdslConnector.Connect(adslName, account, pwd);
            result = true;
            return result;
        }

        public void Disconnection()
        {
            var adslName = ConfigurationManager.AppSettings["AdslName"];
            AdslConnector.Disconnect(adslName);
        }

        //获取内网IP
        private IPAddress GetInternalIP()
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adapter in nics)
            {
                foreach (var uni in adapter.GetIPProperties().UnicastAddresses)
                {
                    if (uni.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        return uni.Address;
                    }
                }
            }
            return null;
        }
    }
}